"""训练记录数据模型"""
from pydantic import BaseModel
from typing import Optional, List, Dict, Any
from datetime import datetime
from enum import Enum


class TrainingSessionStatus(str, Enum):
    """训练会话状态"""
    ACTIVE = "active"
    PAUSED = "paused"
    COMPLETED = "completed"
    ABANDONED = "abandoned"


class TrainingSessionBase(BaseModel):
    """训练会话基础模型"""
    user_id: str
    plan_id: Optional[str] = None


class TrainingSessionCreate(TrainingSessionBase):
    """创建训练会话模型"""
    pass


class TrainingSession(TrainingSessionBase):
    """训练会话模型"""
    session_id: str
    status: TrainingSessionStatus
    started_at: datetime
    ended_at: Optional[datetime] = None
    total_questions: int = 0
    correct_answers: int = 0
    accuracy_rate: float = 0.0


class AnswerRecord(BaseModel):
    """答题记录模型"""
    record_id: str
    session_id: str
    question_id: str
    user_id: str
    user_answer: str
    correct_answer: str
    is_correct: bool
    time_spent: float  # 秒
    submitted_at: datetime
    error_type: Optional[str] = None  # knowledge, thinking, technique, attention
    error_category: Optional[str] = None


class TrainingPlanBase(BaseModel):
    """训练计划基础模型"""
    user_id: str
    duration_days: int
    daily_target_hours: float
    daily_target_questions: int


class TrainingPlanCreate(TrainingPlanBase):
    """创建训练计划模型"""
    pass


class TrainingPlan(TrainingPlanBase):
    """训练计划模型"""
    plan_id: str
    created_at: datetime
    started_at: Optional[datetime] = None
    completed_at: Optional[datetime] = None
    status: str  # active, completed, paused
    progress: Dict[str, Any] = {}
    
    class Config:
        from_attributes = True


class PhasePlan(BaseModel):
    """阶段计划"""
    phase: int
    name: str
    duration_days: int
    start_day: int
    end_day: int
    focus_areas: List[str]
    target_accuracy: float

